package com.srzk.youthleagueback.mapper;

import com.srzk.youthleagueback.pojo.Meeting;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface MeetingMapper {

    @Insert("insert into meeting (user, year, type ,date ,address,host,subject,count,content,`condition`,summary)"+
            "values (#{meeting.user}, #{meeting.year},#{meeting.type},#{meeting.date},#{meeting.address},#{meeting.host}"+
            ",#{meeting.subject},#{meeting.count},#{meeting.content},#{meeting.condition},#{meeting.summary})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int insert(@Param("meeting")Meeting record);

    @Select("SELECT * FROM meeting WHERE user = #{user} AND year = #{year} AND type = #{type}")
    List<Meeting> selectByPrimaryKeyList(@Param("user")String user,@Param("year")String year,@Param("type")int type);

    @Select("SELECT * FROM meeting WHERE year = #{year} AND type = #{type}")
    List<Meeting> selectByGrade(@Param("year")String year,@Param("type")int type);

    @Select("SELECT * FROM meeting WHERE user = #{user} AND type = #{type}")
    List<Meeting> selectAll(@Param("user")String user,@Param("type")int type);

    @Select("SELECT * FROM meeting WHERE id = #{id} AND user = #{user} AND year = #{year} AND type = #{type}")
    Meeting selectByPrimaryKey(@Param("user")String user,@Param("year")String year,@Param("type")int type,@Param("id")int id);

    @UpdateProvider(type = MeetingProvider.class,method = "updateMeeting")
    int updateByPrimaryKey(Meeting record);

    @Delete("DELETE FROM meeting WHERE user = #{user} AND year = #{year} AND type = #{type} AND id = #{id}")
    int deleteByUserAndYearAndTypeAndId(@Param("user")String user,@Param("year")String year,@Param("type")int type,@Param("id")int id);

}